<?php
	include_once(realpath(dirname(__FILE__)) . "/../../../../classes/Baseobj.class.php");
	include_once(realpath(dirname(__FILE__)) . "/../classes/Public_api.php");


	class Mailjet_campagne_envoi extends Baseobj{


		var $id;
		var $dossier;
		var $campagne;
		var $liste;
		var $emailfrom;
		var $nomfrom;
		var $date;
		var $statut;

		var $table="mailjet_campagne_envoi";
		var $bddvars = array("id", "dossier", "campagne", "liste", "emailfrom", "nomfrom", "date", "statut");		
				
		function Mailjet_campagne_envoi(){
			$this->Baseobj();

			include(realpath(dirname(__FILE__)) . "/../config.php");

			$this->api = new Public_api();
			$this->api->apiKey = $cle;
			$this->api->secretKey = $secret;
		}
		
		function charger($campagne){
		      return $this->getVars("select * from $this->table where campagne=\"$campagne\"");
        }
        
		function charger_dossier($dossier){
		      return $this->getVars("select * from $this->table where dossier=\"$dossier\"");
        }      
        
		function stat($type){
			// sent, open, click, bounce, spam, total
			$this->api->sendRequest("messageList", array("custom_campaign" => $this->campagne));
			$xml = simplexml_load_string($this->api->_response);
			$this->api->sendRequest("messageStatistics", array("id" => $xml->result->item->id));
			$xml = simplexml_load_string($this->api->_response);
			return $xml->result->$type;			
		}
          
	}


?>